<script setup>
	import FirstTitle from "@comp/FirstTitle";
	import {
		Editor,
		Toolbar
	} from "@wangeditor/editor-for-vue";
	import {
		onMounted
	} from "vue";
	import {
		searchDataQbxx
	} from "@/api/search";
	import {
		addOrUpdateQbxx
	} from "@/api/addOrUpdate";


	const city = window.globalObj.name;
	const editorRef = shallowRef();
	const editorRef1 = shallowRef();

	const toolbarConfig = {};
	const toolbarConfig1 = {};
	const editorConfig = {
		placeholder: "请输入内容..."
	};
	const mode = ref("default");
	const mode1 = ref("default");

	// 加载html
	const initHtml = () => {
		searchDataQbxx({
			m: "指控系统"
		}).then((res) => {
			const {
				data
			} = res
			valueHtml.value = data.find((x) => x.k === "指挥所指控系统")?.v || "";
			valueHtml1.value = data.find((x) => x.k === "指挥所对外通联")?.v || "";
		})
	};
	

	const handleCreated = (editor) => {
		editorRef.value = editor; // 记录 editor 实例，重要！
	};
	const handleCreated1 = (editor) => {
		editorRef1.value = editor; // 记录 editor 实例，重要！
	};

	const valueHtml = ref(
		"设备调配：一体化指挥平台、便携指挥平台、车载指挥平台。<br/>软件部署：数字预案软件、文电传输软件、综管数据软件。<br/>数据加载：指挥所数据、警报器数据、人防工程数据、疏散地域数据、掩蔽地域数据、重要目标数据、人防专业队数据、医疗卫生数据、消防救援单位数据、空情预警信息系统数据、主要地标数据、敏感电磁目标数据、三大运营商数据、生活及工程物资数据。<br/>业务引接：预案生成、指挥作业、文电传输、视频监控、视频指挥。"
	);

	const valueHtml1 = ref(
		"主用手段：光纤通信网，短波通信网，北斗导航通信网，散射通信网，散射通信网，北斗导航通信网，人防专网4G/5G，公网4G/5G，简易信号通信。<br/>备用手段：光纤通信网。<br/>保底手段：光纤通信网。"
	)


	const saveProgramme = () => {
		ElMessageBox.confirm(`确定要保存吗?`, "警告", {
			confirmButtonText: "确定",
			cancelButtonText: "取消",
			type: "warning",
			customClass: "message-box",
		}).then(() => {
			addOrUpdateQbxx({
					m: "指控系统",
					data: [{
							k: "指挥所指控系统",
							v: valueHtml.value,
						},
						{
							k: "指挥所对外通联",
							v: valueHtml1.value,
						}
					],
				})
				.then((result) => {
					if (result.code === 200) {
						ElMessage.success("操作成功");
						initHtml();
					} else {
						ElMessage.error(result.msg);
					}
				})
				.catch(() => {});
		});
	}

	onMounted(() => {
		initHtml();

	});
	onBeforeUnmount(() => {
		const editor = editorRef.value;
		const editor1 = editorRef1.value;
		if (!editor) return;
		if (!editor1) return;
		editor.destroy();
		editor1.destroy();
	});
</script>
<template>
	<div class="">

		<div class="top-15">
			主要明确指挥所指控系统的设备调配、软件部署、数据加载、业务引接，指挥所对外通联的主用、备用、保底手段等。
		</div>
		<FirstTitle name="指挥所指控系统" class="top-15" />
		<div style="border: 1px solid #ccc" class="top-15">
			<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef" :defaultConfig="toolbarConfig"
				:mode="mode" />
			<Editor style="height: 500px; overflow-y: hidden" v-model="valueHtml" :defaultConfig="editorConfig"
				:mode="mode" @onCreated="handleCreated" />
		</div>

		<FirstTitle name="指挥所对外通联" class="top-15" />
		<div style="border: 1px solid #ccc" class="top-15">
			<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef1" :defaultConfig="toolbarConfig1"
				:mode="mode1" />
			<Editor style="height: 500px; overflow-y: hidden" v-model="valueHtml1" :defaultConfig="editorConfig"
				:mode="mode1" @onCreated="handleCreated1" />
		</div>



		<div class="flex-justify-end top-20">
			<el-button type="primary" class="save-btn" @click="saveProgramme">保存</el-button>
		</div>
	</div>
</template>
<style scoped lang="scss"></style>